unit MatchingOptionsForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, NCore, NUtils, NBiometrics;

type
  TMatchingOptionsForm = class(TForm)
    Label3: TLabel;
    ModeComboBox: TComboBox;
    Label4: TLabel;
    FARComboBox: TComboBox;
    Label5: TLabel;
    MaximalRotationTextBox: TEdit;
    CancelButton: TButton;
    OkButton: TButton;
    DefaultButton: TButton;
    Panel1: TPanel;
    DegreesLabel: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure DefaultButtonClick(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
  private
    scannerModes: TArrayOfTScannerMode;
    okPressed : boolean;
  public
    property  okPress:boolean read okPressed;
    procedure FillModes();
    property  ExtractorMode: TArrayOfTScannerMode write scannerModes;
    procedure setMode(Mode: Integer);
    function  getMode:Integer;
    procedure setFAR(genFar: string);
    function  getFAR: string;
  end;

implementation

{$R *.dfm}

procedure TMatchingOptionsForm.FormCreate(Sender: TObject);
begin
 okPressed := false;
 FARComboBox.Items.Add(FloatToStr(0.1));
 FARComboBox.Items.Add(FloatToStr(0.01));
 FARComboBox.Items.Add(FloatToStr(0.001));
end;

procedure TMatchingOptionsForm.FillModes();
 var i: Integer;
begin
 for i := 0 to Length(scannerModes) - 1 do
 begin
  ModeComboBox.AddItem(scannerModes[i].Name, TObject(scannerModes[i].Code));
 end;
 ModeComboBox.Sorted := true;
end;

procedure TMatchingOptionsForm.setMode(Mode: Integer);
 var i, index: Integer;
begin
 index := 0;
 for i := 0 to ModeComboBox.Items.Count - 1 do
 begin
  if (Integer(ModeComboBox.Items.Objects[i]) = Mode) then
  begin
   index := i;
  end;
 end;
 ModeComboBox.ItemIndex := index;
end;

function TMatchingOptionsForm.getMode:Integer;
begin
 Result := Integer(ModeComboBox.Items.Objects[ModeComboBox.ItemIndex]);
end;

procedure TMatchingOptionsForm.setFAR(genFar: string);
begin
 if (FARComboBox.Items.IndexOf(genFar) = -1) then
 begin
  FARComboBox.Items.Add(genFar);
 end;
 FARComboBox.ItemIndex := FARComboBox.Items.IndexOf(genFar);
end;

function TMatchingOptionsForm.getFAR: string;
begin
 Result := FARComboBox.Text;
end;

procedure TMatchingOptionsForm.DefaultButtonClick(Sender: TObject);
begin
 setMode(N_MODE_GENERAL);
 setFAR('0.01');
 MaximalRotationTextBox.Text := '180';
end;

procedure TMatchingOptionsForm.OkButtonClick(Sender: TObject);
 var tempInteger: Integer;
     tempDouble: Double;
begin
 try
                             
  tempInteger := StrToInt(MaximalRotationTextBox.Text);
  If (tempInteger < 0) Or (360 < tempInteger) Then
  begin
   MaximalRotationTextBox.SetFocus;
   raise Exception.Create('Matching maximal rotation should be in rage [0,180]');
  end;

  tempDouble := StrToFloat(Trim(getFAR));
  If (tempDouble < 0) Or (100 < tempDouble) Then
  begin
   FARComboBox.SetFocus;
   raise Exception.Create('Matching FAR should be in rage [0,100]');
  end;

  okPressed := true;

  Self.Close;
 except
 on E:Exception do
  MessageDlg('Error: ' + E.Message,
     mtError, [mbOK], 0)
 end;
end;

end.
